package httplib;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public abstract class HTMLFileHandler {
	public abstract byte[] getResponseFile();
	
	public abstract String getResponseHeader();
	
	public abstract String handleFile(String file);
	
	protected byte[] getBytesFromFile(File file) throws IOException {
		
		InputStream is = new FileInputStream(file);
	    
        // Get the size of the file
        int length = (int)file.length();
    
        // You cannot create an array using a long type.
        // It needs to be an int type.
        // Before converting to an int type, check
        // to ensure that file is not larger than Integer.MAX_VALUE.
        if (length > Integer.MAX_VALUE) {
            // File is too large
        	throw (new IOException(file.getName() + " is too large"));
        }
        // Create the byte array to hold the data
        byte[] bytes = new byte[length];
        
        is.read(bytes);
        
        // Close the input stream and return bytes
        is.close();
        return bytes;
    }
}
